package com.codegenerate.demo.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import org.springframework.util.StringUtils;
import com.fasterxml.jackson.annotation.JsonIgnore;

import java.io.Serializable;
import java.time.LocalDateTime;


@TableName(value ="g_table")
public class GTable implements Serializable {
    @TableId(value = "id", type = IdType.AUTO)
    private long id;









    /**
     *
     */
    @TableField(value = "table_name")
    private String tableName;




    /**
     *
     */
    @TableField(value = "table_name_chinese")
    private String tableNameChinese;




    /**
     *
     */
    @TableField(value = "del_state")
    private int delState;









    public long getId() {
        return id;
    }
    public void setId(long id) {
        this.id = id;
    }

    public String getTableName() {
        return tableName;
    }
    public void setTableName(String tableName) {
        this.tableName = tableName;
    }

    public String getTableNameChinese() {
        return tableNameChinese;
    }
    public void setTableNameChinese(String tableNameChinese) {
        this.tableNameChinese = tableNameChinese;
    }

    public int getDelState() {
        return delState;
    }
    public void setDelState(int delState) {
        this.delState = delState;
    }




    /**
     * build
     */
    public static GTable build(){
        GTable tempEntity = new GTable();
        return tempEntity;
    }

    /**
     * build
     */
    public  static void setDefaultValue(GTable temp){

        if(temp.getId()<=0){
            temp.setId(0);
        }

        if(StringUtils.isEmpty(temp.getTableName())){
            temp.setTableName("");
        }

        if(StringUtils.isEmpty(temp.getTableNameChinese())){
            temp.setTableNameChinese("");
        }

        if(temp.getDelState()<=0){
            temp.setDelState(1);
        }



    }

    @JsonIgnore
    public LambdaQueryWrapper<GTable> getQueryAll() {
        var  query = new QueryWrapper<GTable>().lambda();

        if(this.id>0){
            query.eq(GTable::getId, this.id);
        }

        if(!StringUtils.isEmpty(this.tableName)){
            query.eq(GTable::getTableName, this.tableName);
        }

        if(!StringUtils.isEmpty(this.tableNameChinese)){
            query.eq(GTable::getTableNameChinese, this.tableNameChinese);
        }

        if(this.delState>0){
            query.eq(GTable::getDelState, this.delState);
        }



        return  query;

    }

    @JsonIgnore
    public static LambdaQueryWrapper<GTable> getQuery(){
        var query = new QueryWrapper<GTable>().lambda();
        return query;
    }


    @JsonIgnore
    public LambdaUpdateWrapper<GTable> getUpdateWrapper() {
        var  updateWrapper = new UpdateWrapper<GTable>().lambda();

        if(this.id>0){

            updateWrapper.eq(GTable::getId, this.id);

        }

        if(!StringUtils.isEmpty(this.tableName)){

            updateWrapper.set(GTable::getTableName, this.tableName);

        }

        if(!StringUtils.isEmpty(this.tableNameChinese)){

            updateWrapper.set(GTable::getTableNameChinese, this.tableNameChinese);

        }

        if(this.delState>0){

            updateWrapper.set(GTable::getDelState, this.delState);

        }



        return updateWrapper;
    }

}